<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="/WEB-INF/tlds/shiro.tld" %>

<%@include file="/WEB-INF/views/include/inc.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@include file="/WEB-INF/views/include/head.jsp"%>
<!-- jqgrid-->
<link
	href="<%=contextPath%>/assets/hplus/css/plugins/jqgrid/ui.jqgridffe4.css?0820"
	rel="stylesheet">
	<link
	href="<%=contextPath%>/assets/contextmenu/context.standalone.css"
	rel="stylesheet">
<style type="text/css">
.ui-jqgrid .ui-pg-selbox, .ui-jqgrid .ui-jqgrid-toppager .ui-pg-selbox {
	padding: 0 0 3px 3px;
}
</style>
</head>
<body >
	<div class="" >
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox " style="margin-bottom: 0px;">
					<div class="ibox-title" style="border-color: white;">
						 <div class="row">
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input id="keyword" type="text" placeholder="请输入关键词" class="input-sm form-control"> <span class="input-group-btn">
                                        <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a> </span>
                                </div>
                            </div>
                        </div>
					</div>
					<div class="ibox-content">

						<div class="jqGrid_wrapper">
							<table id="table_list"></table>
							<div id="pager_list"></div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 全局js -->
	<%@include file="/WEB-INF/views/include/foot.jsp"%>
	<!-- Peity -->
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/peity/jquery.peity.min.js"></script>

	<!-- jqGrid -->
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
	<script
		src="<%=contextPath%>/assets/hplus/js/plugins/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>

	<!-- 自定义js -->
	<script
		src="<%=contextPath%>/assets/contextmenu/context.js"></script>

	<!-- Page-Level Scripts -->
	<script>
		$(document).ready(function() {
			$.jgrid.defaults.styleUI = "Bootstrap";
			//初始化右键菜单
			context.init({preventDoubleContext: false});
			$("#table_list").jqGrid({
				url: '<%=contextPath%>/sys/user/listData',
				data : {},
				datatype : "json",
				autowidth : true,
				shrinkToFit : true,
				mtype : "post",
				rowNum : 20,
				rowList : [ 10, 20, 30 ],
				colNames : ["id", "用户名", "姓名", "电话", "邮箱", "上次登录时间", "上次登录IP" ,"状态"],
				colModel : [{
					name : "id",
					index : "id",
					hidden:true
				}, {
					name : "username",
					index : "username",
					width : 90
				}, {
					name : "truename",
					index : "truename",
					width : 50
				}, {
					name : "mobile",
					index : "mobile",
					width : 80
				}, {
					name : "email",
					index : "email",
					width : 80
				}, {
					name : "lastLoginTime",
					index : "lastLoginTime",
					width : 80,
					sorttype:"date",
					formatter:"date",
					formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}
				}, {
					name : "lastLoginIp",
					index : "lastLoginIp",
					width : 100
				},{
					name : "locked",
					index : "locked",
					width : 50,
					formatter:function(cellvalue, options, row){
						if(cellvalue==1){
					         return "<a class='btn btn-sm btn-danger'>正常</a>";
					    }else{
					         return "<a class='btn btn-sm btn-primary'>停用</a>";
					    }
					}
				} ],
				height : $(window).height() - 170,
				pager : "#pager_list",
				viewrecords : true,
				hidegrid : false
			});
			
			//表格自适应高宽
			$(window).bind("resize", function() {
				var b = $(".jqGrid_wrapper").width();
				$("#table_list").setGridWidth(b);
				$("#table_list").setGridHeight($(window).height() - 170);
			})
			
			$("#table_list")
			.navGrid('#pager_list',{edit:false,add:false,del:false,search:false}) 
			//是否拥有新增的权限
			<shiro:hasPermission name="sys:user:add">  
			.navButtonAdd('#pager_list',{   
			   caption:"",    
			   buttonicon:"glyphicon glyphicon-plus", 
			   onClickButton: function(){    
				   var isConfirm = true;
  				    parent.layer.open({
			        	title:'新增用户',
			            type: 2,
			            fix:true,
			            end :function(){
			        	    if(isConfirm){
			        	    	$("#table_list").trigger("reloadGrid");
			        	    }
			            },
	 			        cancel:function(index){
	 			        	isConfirm = false;
	 			        },
			            area: ['80%','80%'],
			            content: '<%=contextPath%>/sys/user/addView'
			        });
			   },    
			   position:"first"  
			})
			</shiro:hasPermission>
			;

			$("#find_btn").click(function(){ 
		        var keyword = escape($("#keyword").val()); 
		        $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'keyword':keyword}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		    }); 
			
			//判断右键权限
			<shiro:hasAnyPermission name="sys:user:delete,sys:user:update"> 
			//对表格设置右键菜单
			context.attach('#table_list', [
			<shiro:hasPermission name="sys:user:delete">  
          		{
          			text: '修改',
          			action:function(){
          				var selectedIds = $("#table_list").jqGrid("getGridParam", "selrow");
       				    var rowData = $("#table_list").jqGrid("getRowData",selectedIds);
       				    var isConfirm = true;
       				    parent.layer.open({
	 			        	title:'修改用户',
	 			            type: 2,
	 			            fix:true,
	 			            end :function(){
	 			        	    if(isConfirm){
	 			        	    	$("#table_list").trigger("reloadGrid");
	 			        	    }
	 			            },
		 			        cancel:function(index){
		 			        	isConfirm = false;
		 			        },
	 			            area: ['80%','80%'],
	 			            content: '<%=contextPath%>/sys/user/updateView?id='+rowData.id
	 			        });    
          			}
          		}
          		</shiro:hasPermission>
          		<shiro:hasPermission name="sys:user:delete">  
          		,
          		{text: '删除',
          			action:function(){
          				parent.swal({
          			        title: "您确定要删除该用户吗",
          			        text: "删除后将无法恢复，请谨慎操作！",
          			        type: "warning",
          			        showCancelButton: true,
          			        confirmButtonColor: "#DD6B55",
          			        confirmButtonText: "删除",
          			        closeOnConfirm: true
          			    }, function () {
          			    	var selectedIds = $("#table_list").jqGrid("getGridParam", "selrow");
           				    var rowData = $("#table_list").jqGrid("getRowData",selectedIds);
	           				 $.ajax({url:"<%=contextPath%>/sys/user/delete?id="+rowData.id,
	           						 dataType:'json',
	           						 success:function(data){
	           							if(data.code==200){
	               				    		$("#table_list").trigger("reloadGrid");
	               				    	}else{
	               				    		
	               				    	}
	           						 },
	           						error:function(){
	           							parent.swal("错误", "删除失败，请重试！", "error");
	           						}
	           				 });
          					 parent.layer.close(index);
          			    });
          			}
          		}
          		</shiro:hasPermission>
          		]
          	);
			</shiro:hasAnyPermission>
		});
	</script>

</body>
</html>

